package com.example.basic.web.controller.pharmIn;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.pharmIn.PharmInRecord;
import com.example.basic.web.response.InNoticeResponse;
import com.example.basic.web.response.InPharmResponse;
import com.example.basic.web.service.pharmIn.PharmInRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Api(value  = "入库单", tags = {"入库单"})
@RestController
@RequestMapping("/api/v1/byg/pharmInRecord")
public class PharmInRecordController {

    @Resource
    private PharmInRecordService pharmInRecordService;

    @Log(title = "入库单管理", description = "列表")
    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/queryList")
    public Result<IPage<InPharmResponse>> queryList(
            @ApiParam(name = "searchParam", value = "模糊搜索(遗体名称，拼音码，五笔码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "sex", value = "性别 0-全部") @RequestParam(defaultValue = "0") String sex,
            @ApiParam(name = "pharmCode", value = "库房编码 0-全部") @RequestParam(defaultValue = "0") String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码 0-全部") @RequestParam(defaultValue = "0") String zoneCode,
            @ApiParam(name = "depotCode", value = "库位编码 0-全部") @RequestParam(defaultValue = "0") String depotCode,
            @ApiParam(name = "status", value = "状态 0-全部") @RequestParam(defaultValue = "0") String status,
            @ApiParam(name = "beginTime", value = "开始日期") @RequestParam(required = false) String beginTime,
            @ApiParam(name = "endTime", value = "结束日期") @RequestParam(required = false) String endTime,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<InPharmResponse> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(pharmInRecordService.queryList(queryPage,searchParam,sex,pharmCode,zoneCode,depotCode,status,beginTime,endTime));
    }

    @ApiOperation(value = "入库", notes = "入库")
    @PostMapping("/inPharm")
    public Result<Boolean> inPharm(@ApiParam(name = "inPharmCode", value = "入库单编码") @RequestParam String inPharmCode ) {
        return ResultGenerator.genSuccessResult(pharmInRecordService.inPharm(inPharmCode));
    }

    @ApiOperation(value = "入库单状态更新--入库中", notes = "入库单状态更新--入库中")
    @PostMapping("/modifyStatus")
    public Result<Boolean> modifyStatus(@ApiParam(name = "inPharmCode", value = "入库单编码") @RequestParam String inPharmCode ) {
        return ResultGenerator.genSuccessResult(pharmInRecordService.modifyStatus(inPharmCode));
    }
}
